package com.ck.mybatis.plus.util;



import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class QueryUtil {
//    public static List<QueryFieldEntity> getQueryAutoField(Object object) {
//        List<QueryFieldEntity> list = new ArrayList();
//        Class<?> cls = object.getClass();
//
//        List<Field> fieldList = getFiledsInfo( cls.getName() );
//        if(CollectionUtils.isNotEmpty(fieldList)){
//            for(Field field : fieldList) {
//                field.setAccessible(true);
//                QueryField queryField = field.getAnnotation(QueryField.class);
//                if (queryField == null) {
//                    continue;
//                }
//                QueryFieldEntity entity = new QueryFieldEntity();
//                entity.setIdFieldName(field.getName());
//                entity.setNameFieldName(queryField.nameField());
//                entity.setModule(queryField.module());
//                list.add(entity);
//            }
//        }
//
//
//        /*Field[] fields = cls.getFields();
//        for(Field field:fields) {
//            field.setAccessible(true);
//            QueryField queryField = field.getAnnotation(QueryField.class);
//            if (queryField == null) {
//                continue;
//            }
//            QueryFieldEntity entity = new QueryFieldEntity();
//            entity.setIdFieldName(field.getName());
//            entity.setNameFieldName(queryField.nameField());
//            entity.setModule(queryField.module());
//            list.add(entity);
//        }*/
//        return list;
//    }


    public static List<Field> getFiledsInfo(String className) {
        List<Field> list = new ArrayList<>();
        Class<?> clazz = null;
        try {
            clazz = Class.forName(className);
            Field[] fields = clazz.getDeclaredFields();
            list.addAll(Arrays.asList(fields));
            Class<?> superClazz = clazz.getSuperclass();
            if (superClazz != null) {
                Field[] superFields = superClazz.getDeclaredFields();
                list.addAll(Arrays.asList(superFields));
            }
            return list;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main( String[] args ) throws ClassNotFoundException{
//        EquBaseVO equBaseVO = new EquBaseVO();
//        List<QueryFieldEntity> list = getQueryAutoField( equBaseVO );
//        System.out.println( "list length :" + list.size() );
    }
}
